﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Convertor.Interface;
using Wpf.CommonTools;
using Wpf.CommonTools.SystemExtension;

namespace Convertor.Plugin.StopCondition
{
    [Flags]
    public enum ConditionOptions
    {
        True = 2,
        False = 4
    }

    [Serializable]
    public class ConfigContent : IConfigContent, ISerializable, ICloneable, INotifyPropertyChanged
    {
        private ConditionOptions condition = ConditionOptions.True;

        public ConditionOptions Condition
        {
            get { return condition; }
            set { condition = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("ToolTip")); } }
        }
        private OutputTypes compareTarget = OutputTypes.InputContent;

        public OutputTypes CompareTarget
        {
            get { return compareTarget; }
            set { compareTarget = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("ToolTip")); } }
        }

        public ConfigContent()
        {
        }

        public override string ToString()
        {
            return ToolTip;
        }

        #region IToolTip 成员

        public string ToolTip
        {
            get
            {
                return string.Format(UILanguage.TryFindResource("Plugin_StopCondition_Info"),
                    UILanguage.TryFindResource(compareTarget.ToString()),
                    UILanguage.TryFindResource("Plugin_StopCondition_ConditionOption_" + Condition));
            }
        }

        #endregion

        #region ISerializable 成员

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Condition", Condition, typeof(ConditionOptions));
            info.AddValue("CompareTarget", CompareTarget, typeof(OutputTypes));
        }

        public ConfigContent(SerializationInfo info, StreamingContext context)
        {
            try
            {
                Condition = (ConditionOptions)info.GetValue("Condition", typeof(ConditionOptions));
            }
            catch { }
            try
            {
                CompareTarget = (OutputTypes)info.GetValue("CompareTarget", typeof(OutputTypes));
            }
            catch { }
        }

        #endregion

        #region ICloneable 成员

        public object Clone()
        {
            ConfigContent content = new ConfigContent()
            {
                Condition = this.Condition,
                CompareTarget = this.CompareTarget
            };
            return content;
        }

        #endregion

        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

    }
}
